<?php
    include ('_connect.php');
    $username = $_POST['uname'];
    $password = $_POST['pwd'];
    $email = $_POST['email'];
    // $sex = $_POST['sex'];
    $selectSql = "select * from gzxtable2 where username='$username'";
    
    $result = $mysqli->query($selectSql); 
   var_dump($result->num_rows);
    // var_dump($result);
    if($result->num_rows>0){
        die('用户名已存在');
    }
    // if($result->num_rows>0){
    //     die('用户名已存在');
    // }
    $insertSql = "insert into gzxtable2 (username,password,email,sex) values ('$username','$password','$email','1')";
    var_dump($insertSql);
    $res = $mysqli->query($insertSql); //当sql语句是插入操作时，返回结果是受印象行数
    var_dump($res);
    if($res){
        echo "<script>alert('注册成功');location.href='../src/html/index.html';</script>";
    }else{
        // echo "<script>alert('注册失败');location.href='../src/html/index.html';</script>";
        echo "<script>alert('注册失败');</script>";
    }
?>